<?php


namespace App\Services\Agora;
require_once(dirname(__FILE__) . "/lib/src/RtmTokenBuilder.php");

class RtmTokenService extends BaseService
{
    private $expireTimeInSeconds = 86400;//令牌过期时间

    //获取令牌
    public function get($userId)
    {
        $role = \RtmTokenBuilder::RoleRtmUser;
        $currentTimestamp = (new \DateTime("now", new \DateTimeZone('UTC')))->getTimestamp();
        $privilegeExpiredTs = $currentTimestamp + $this->expireTimeInSeconds;
        $token = \RtmTokenBuilder::buildToken($this->appid, $this->appCertificate, $userId, $role, $privilegeExpiredTs);
        return $token;
    }
}
